// SA_BPA.cpp: implementation of the CSA_BPA class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "../../Include/Swi/SA_BPA.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CSA_BPA::CSA_BPA()
{
	m_chType = 'S';
	m_chSubType = 'A';
	m_chChangeCode = ' ';

	m_dT1 = 0;
	m_dT2 = 0;
	m_dT3 = 0;
	m_dT4 = 0;
	m_dT5 = 0;
	m_dT6 = 0;
	m_dK1 = 0;
	m_dK2 = 0;
	m_dK = 0;
	m_dA = 0;
	m_dP = 0;
	m_dLIMIT_max = 0;
	m_dLIMIT_min = 0;
	m_dMva = 0;

	m_strCardType[0] = 'S';

}

CSA_BPA::CSA_BPA(CSA_BPA &saBPA):CUnit_BPA(saBPA)
{
	m_dT1 = saBPA.m_dT1;
	m_dT2 = saBPA.m_dT2;
	m_dT3 = saBPA.m_dT3;
	m_dT4 = saBPA.m_dT4;
	m_dT5 = saBPA.m_dT5;
	m_dT6 = saBPA.m_dT6;
	m_dK1 = saBPA.m_dK1;
	m_dK2 = saBPA.m_dK2;
	m_dK = saBPA.m_dK;
	m_dA = saBPA.m_dA;
	m_dP = saBPA.m_dP;
	m_dLIMIT_max = saBPA.m_dLIMIT_max;
	m_dLIMIT_min = saBPA.m_dLIMIT_min;
	m_dMva = saBPA.m_dMva;
}

CSA_BPA::~CSA_BPA()
{

}

bool CSA_BPA::FillEx(char *buffer)
{
	bool bResult = CUnit_BPA::FillEx(buffer);

	if (!bResult)
	{
		printf("Error in (CSA_BPA::FillEx): no basic information!\n");
		return false;
	}

	if (strlen(buffer)<17)
		return true;

	m_dT1 = StrToDouble(&buffer[16],4,4);
	if(EndOfSec(&buffer[16],4))
		return true;

	m_dT2 = StrToDouble(&buffer[20],4,4);
	if(EndOfSec(&buffer[20],4))
		return true;

	m_dT3 = StrToDouble(&buffer[24],4,3);
	if(EndOfSec(&buffer[24],4))
		return true;

	m_dT4 = StrToDouble(&buffer[28],4,3);
	if(EndOfSec(&buffer[28],4))
		return true;

	m_dT5 = StrToDouble(&buffer[32],4,3);
	if(EndOfSec(&buffer[32],4))
		return true;

	m_dT6 = StrToDouble(&buffer[36],4,3);
	if(EndOfSec(&buffer[36],4))
		return true;

	m_dK1 = StrToDouble(&buffer[40],5,3);
	if(EndOfSec(&buffer[40],5))
		return true;

	m_dK2 = StrToDouble(&buffer[45],5,3);
	if(EndOfSec(&buffer[45],5))
		return true;

	m_dK = StrToDouble(&buffer[50],5,3);
	if(EndOfSec(&buffer[50],5))
		return true;

	m_dA = StrToDouble(&buffer[55],5,3);
	if(EndOfSec(&buffer[55],5))
		return true;

	m_dP = StrToDouble(&buffer[60],5,3);
	if(EndOfSec(&buffer[60],5))
		return true;

	m_dLIMIT_max = StrToDouble(&buffer[65],5,3);
	if(EndOfSec(&buffer[65],5))
		return true;

	m_dLIMIT_min = StrToDouble(&buffer[70],5,3);
	if(EndOfSec(&buffer[70],5))
		return true;

	m_dMva = StrToDouble(&buffer[75],4,0);
	if(EndOfSec(&buffer[75],4))
		return true;

	return true;
}

bool CSA_BPA::UpdateEx(char *buffer)
{
	bool bResult = CUnit_BPA::UpdateEx(buffer);

	if (!bResult)
	{
		printf("Error in (CSA_BPA::UpdateEx): impossible!\n");
		return false;
	}

	DoubleToStr(m_dT1,&buffer[16],4,4);
	DoubleToStr(m_dT2,&buffer[20],4,4);
	DoubleToStr(m_dT3,&buffer[24],4,3);
	DoubleToStr(m_dT4,&buffer[28],4,3);
	DoubleToStr(m_dT5,&buffer[32],4,3);
	DoubleToStr(m_dT6,&buffer[36],4,3);
	DoubleToStr(m_dK1,&buffer[40],5,3);
	DoubleToStr(m_dK2,&buffer[45],5,3);
	DoubleToStr(m_dK,&buffer[50],5,3);
	DoubleToStr(m_dA,&buffer[55],5,3);
	DoubleToStr(m_dP,&buffer[60],5,3);
	DoubleToStr(m_dLIMIT_max,&buffer[65],5,3);
	DoubleToStr(m_dLIMIT_min,&buffer[70],5,3);
	DoubleToStr(m_dMva,&buffer[75],4,0);

	return true;
}